<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_wjyl_ng {
        background-color: #254060;
        height: 435px;
        color: white;
        overflow: auto;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    table {
        width: 100%;
        table-layout: fixed;
        word-wrap: break-word;
    }

    td {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟安创</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:24%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn " onclick="refresh()">
                <span class="aui-iconfont refresh"></span>
            </a>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>文件查阅</p>
            </div>
        </div>


        <div class="aui-flex-col aui-flex-center" style="margin-top: 1%;">
            <div class="aui-flex-item-12">
                <div class="aui-flex-col pa_wjyl_ng">
                    <div class="aui-flex-item-12">
                        <div style="height: 100%;width: 100%;">
                            <table class="table" border="1px solid gray" cellspacing="0" cellpadding="0">
                                <thead>
                                    <tr style="text-align: center;color: white;font-size: 20px;height: 40px;">
                                        <td algin='center' style="width:5%">序号</td>
                                        <td algin='center' style="width:25%">文件名</td>
                                        <td algin='center' style="width:22%">上传时间</td>
                                        <td algin='center' style="width:16%">上传人员</td>
                                        <td algin='center' style="width:15%">文件状态</td>
                                        <td algin='center' style="width:16%">文件预览</td>
                                    </tr>
                                </thead>
                                <tbody id="fileDataHtml">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);

        //1:查询文件查询列表数据
        doSearch();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //查询
    function doSearch() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/documentView";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {

                    //班組賦值
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: white;font-size: 18px;height:50px;'>";
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='file_original_name'>" + list[i].file_original_name + "</td>";
                        html += "<td name='create_date'>" + list[i].create_date + "</td>";
                        html += "<td name='username'>" + list[i].username + "</td>";
                        html += "<td name='effective'>" + list[i].effective + "</td>";
                        html += "<td name='teamName'> <button style = 'background-color:green' onclick='openFile(\"" + list[i].docid + "\",\"" + list[i].file_original_name + "\")'>预览</button></td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("fileDataHtml"), html);
                } else {
                    $api.html($api.byId("fileDataHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //文件预览
    function openFile(docId, fileName) {
        var serverUrl = localStorage.getItem('serverUrl');
        var downloadUrl = serverUrl + `/app/openFile/` + docId;
        api.download({
            url: downloadUrl,
            report: true,
            savePath: 'fs://' + fileName,
        }, function (ret, err) {
            if (ret && 1 == ret.state) { /* 下载完成 */
                // console.log("下载成功savePath:" + ret.savePath);

                // 打开文件
                var docReader = api.require('docReader');

                docReader.open({
                    path: 'fs://' + fileName
                }, function (ret, err) {
                    if (ret.status) {
                        console.log("文件打开成功：" + ret);
                    } else {
                        alert(JSON.stringify(err));
                    }
                });
            }

            if (ret && 2 == ret.state) {
                console.log("下载失败");
            }
        });
    }

    //刷新按钮
    function refresh() {

        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        doSearch();
    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>